package cn.iocoder.yudao.module.enterprise.controller.admin.datamanage;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.enterprise.controller.admin.datamanage.vo.*;
import cn.iocoder.yudao.module.enterprise.convert.datamanage.DataManageConvert;
import cn.iocoder.yudao.module.enterprise.dal.dataobject.datamanage.DataManageDO;
import cn.iocoder.yudao.module.enterprise.service.datamanage.DataManageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name =  "管理后台 - 数据管理计划")
@RestController
@RequestMapping("/enterprise/data-manage")
@Validated
public class DataManageController {

    @Resource
    private DataManageService dataManageService;

    @PostMapping("/create")
    @Operation(summary = "创建数据管理计划")
    @PreAuthorize("@ss.hasPermission('enterprise:data-manage:create')")
    public CommonResult<Long> createDataManage(@Valid @RequestBody DataManageCreateReqVO createReqVO) {
        return success(dataManageService.createDataManage(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新数据管理计划")
    @PreAuthorize("@ss.hasPermission('enterprise:data-manage:update')")
    public CommonResult<Boolean> updateDataManage(@Valid @RequestBody DataManageUpdateReqVO updateReqVO) {
        dataManageService.updateDataManage(updateReqVO);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得数据管理计划")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('enterprise:data-manage:query')")
    public CommonResult<DataManageRespVO> getDataManage(@RequestParam("id") Long id) {
        DataManageDO dataManage = dataManageService.getDataManage(id);
        return success(DataManageConvert.INSTANCE.convert(dataManage));
    }

    @PostMapping("/list")
    @Operation(summary = "获得数据管理计划列表")
    @PreAuthorize("@ss.hasPermission('enterprise:data-manage:query')")
    public CommonResult<List<DataManageListRespVO>> getDataManageList(@Valid @RequestBody DataManageListReqVO listReqVO) {
        return success(dataManageService.getDataManageList(listReqVO));
    }

}
